require(["config"],function(){
	require(["jquery","com","own"],function($,com,own){
		com(own);
		//手机号验证
		var phone = own.getId("inp1");
		var login = own.getId("login");
		var yz = own.getId("inp2");
		var agree = own.getId("agree");
		var sub = own.getClass("enroll_box_btn")[0];
		var tz = own.getClass("enroll_box_hd")[0];
		var bg = own.getClass("enroll_box_bg")[0];
		var txt = own.getClass("enroll_box_txt")[0];
		var tsxx = own.getClass("enroll_tsxx");
		var phoneF = false;
		var tzF = false;
		phone.onfocus = yz.onfocus = function(){
			this.style.borderColor = "#7abd54";
			tsxx[0].style.display = "none";
		}
		phone.onblur = yz.onblur = function(){
			this.style.borderColor = "#e1e1e1";
		}            
		tz.onmousedown = function(e){
			tsxx[1].style.display = "none";
			var e = e || window.event;
			var x = e.clientX - tz.offsetLeft;
			document.onmousemove = function(e){
				var e = e || window.event;
				var mixW = 270 - tz.offsetWidth;
				var l = e.clientX - x;
				if(l < 0){
					l = 0;
					tzF = false;
				}
				if(l > mixW){
					l = mixW;
					txt.innerHTML = "验证通过";
					txt.style.color = "#fff";
					tz.style.background = "url(images/index/verify_2.png) no-repeat center #fff";
					tz.onmousedown = null;
					tzF = true;
					this.onmousemove = null;
				}
				tz.style.left = l + "px";
				bg.style.width = l + "px";
				return false;
			}
			document.onmouseup = function(){
				var left = tz.offsetLeft;
				if(left < 226){
					left = 0;
				}else{
					left = left;
				}
				tz.style.left = left + "px";
				bg.style.width = left + "px";
				document.onmousemove = null;
				document.onmouseup = null;
			}
		}
		agree.onclick = function(){
			if(agree.checked){
				sub.style.background = "rgb(229, 30, 19)";
				sub.onclick = function(){
					regist();
				}
			}else{
				sub.style.background = "#ccc";
				sub.onclick = function(){
					return false;
				}
			}
		}
		sub.onclick = function(){
			regist();
		}
		function regist(){
			var phoneV = phone.value;
			var reg = /^1[3|4|5|7|8][0-9]{9}$/;
			if(reg.test(phoneV)){
				phoneF = true;
			}else{
				phoneF = false;
				tsxx[0].style.display = "block";
				phone.style.borderColor = "red";
			}
			if(!tzF){
				tsxx[1].style.display = "block";
			}
			if(reg.test(phoneV) && tzF){
				var str = phoneV.slice(5,11)
				own.setCookie(phoneV,str,15);
				login.style.display = "block";
			}
		}
	})
})
